<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

   <script src="js/haha.js"></script>
    <style>

        fieldset{
            width: 500px;
            margin: 100px auto;

        }
    </style>
</head>
<body>
<div id="app">

    <fieldset>
        <legend>登录</legend>
        <el-form :model="info" status-icon :rules="rules" ref="info" label-width="100px" class="demo-ruleForm">
            <el-form-item label="账号" prop="username">
                <el-input type="text" v-model="info.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="info.password" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm('info')">提交</el-button>
                <el-button @click="resetForm('info')">重置</el-button>
            </el-form-item>
        </el-form>
    </fieldset>
</div>

<script>
	
	

    var app = new Vue({
        el:"#app",
        data:{
            info:{},
            rules:{
                username: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ]
            }
        },
        methods:{
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // 发送请求到后台
                        $.post(BASE_URL+"/emp/login",app.info,function(backData){

                            if(backData.code == 200){
								document.cookie = "islogin=ture";
                                window.location.href = "/static/main.html"
                            }else{
                                app.$message.error(backData.msg);
                            }

                        })

                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    });


</script>

</body>
</html>